//
//  FyUILib.h
//  FyUILib
//
//  Created by luoc on 16/2/6.
//  Copyright © 2016年 luoc. All rights reserved.
//

#import <Foundation/Foundation.h>


enum
{
    XMLFILE_ENCODING_UTF8 = 0,
    XMLFILE_ENCODING_UNICODE = 1,
    XMLFILE_ENCODING_ASNI = 2,
};


@class CMarkup;
@interface CMarkupNode : NSObject

- (void)SetOwner:(CMarkup*)pOwner pos:(int)iPos;

- (BOOL)IsValid;
- (CMarkupNode*)GetParent;
- (CMarkupNode*)GetSibling;
- (CMarkupNode*)GetChild;
- (CMarkupNode*)GetChild:(const char*)pstrName;

- (BOOL)HasSiblings;
- (BOOL)HasChildren;
- (const char*)GetName;
- (const char*)GetValue;

- (BOOL)HasAttributes;
- (BOOL)HasAttribute:(const char*)pstrName;
- (int)GetAttributeCount;
- (const char*)GetAttributeName:(int)index;
- (const char*)GetAttributeValueWithIndex:(int)index;
- (const char*)GetAttributeValueWithName:(const char*)pstrName;
- (BOOL)GetAttributeValueWithIndex:(int)index :(char*)pstrValue :(int)cchMax;
- (BOOL)GetAttributeValueWithName:(char*)pstrName :(char*)pstrValue :(int)cchMax;

- (void)_MapAttributes;
@end


typedef struct tagXMLELEMENT
{
    unsigned long iStart;
    unsigned long iChild;
    unsigned long iNext;
    unsigned long iParent;
    unsigned long iData;
} XMLELEMENT;

@interface CMarkup : NSObject
{
    char*           _pStrXML;
}
- (void)SetXml:(const char*)pstrXML;
- (char*)GetXmlStr;
- (int)GetXMLElementsiStart:(int)iPos;
- (int)GetXMLElementsiData:(int)iPos;
- (int)GetXMLElementsiChild:(int)iPos;
- (int)GetXMLElementsiNext:(int)iPos;
- (int)GetXMLElementsiParent:(int)iPos;

- (BOOL)Load:(const char*)pstrXML;
- (BOOL)LoadFromeFile:(const char*)pstrFileName;
- (void)Release;
- (BOOL)IsValid;

- (void)SetPreserveWhitespace:(BOOL)bPreserve;
- (void)GetLastErrorMessage:(const char*)pstrMessage :(int)cchMax;
- (void)GetLastErrorLocation:(const char*)pstrSource :(int)cchMax;

- (CMarkupNode*)GetRoot;

- (BOOL)_Parse;
- (BOOL)_Parse:(char**)pstrText :(unsigned long)iParent;
- (XMLELEMENT*)_ReserveElement;
- (void)_SkipWhitespace:(char**)pstr;
- (void)_SkipIdentifier:(char**)pstr;
- (BOOL)_ParseData:(char**)pstrText :(char**)pstrData :(char)cEnd;
- (void)_ParseMetaChar:(char**)pstrText :(char**)pstrDest;
- (BOOL)_ParseAttributes:(char**)pstrText;
- (BOOL)_Failed:(const char*)pstrError :(const char*)pstrLocation;
@end
